<?php
set_time_limit(0);

define('IN_ECS',true);
$cur_path = dirname(__FILE__);
$zoshow_dir = dirname($cur_path).'/zoshow/';
include($zoshow_dir.'includes/init.php');
$lock_file_name = '/tmp/sendmail.lck';
if($_GET['act'] == 'unlock')
{
	unlink($lock_file_name);
	exit;
}
if(file_exists($lock_file_name) && $_GET['act'] != 'cancel')
{
	die('In Use');
	exit;
}
file_put_contents($lock_file_name,'lck');
try{
$dirname = "/var/spool/zoshow";
if ($handle = opendir($dirname)) 
{
    while (false !== ($file = readdir($handle))) 
    {
        if (is_file($dirname.'/'.$file)) 
        {
        	if($_GET['act'] == 'cancel')
        	{
        		unlink($dirname.'/'.$file);
        	}
        	else 
        	{
	            send_file($dirname.'/'.$file);
	            sleep(1);
        	}
        }
    }
    closedir($handle);
}
}
catch(Exception $e)
{
	echo $e->getMessage();
}

unlink($lock_file_name);

function send_file($file_name)
{
	if(is_file($file_name))
	{
		$content = file_get_contents($file_name);
		$contents = explode('€',$content);
		@send_mail("亲爱的",$contents[0],$contents[1],$contents[2],1);
		echo "$contents[0],$contents[1],$contents[2]";
		unlink($file_name);
		return true;
	}
	return false;
}
?>